package cn.panda.edu.controller;

import cn.panda.edu.model.Judge;
import cn.panda.edu.service.JudgeService;
import cn.panda.edu.util.ResultDataUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 
 * 类描述：  对判断题的CURD操作
 * @author: 张春雷
 * @date： 2018-01-18 上午11:00:32
 */
@RestController
@RequestMapping(value="/api/teacher/courseware")
public class TeacherJudgeController {

	@Autowired
	private JudgeService judgeService;
	
	@ApiOperation(value="通过ID获取判断题" , notes="")
    @ApiImplicitParam(name = "judgeId", value = "判断题ID", required = true, dataType = "Integer",paramType="form")
	@RequestMapping(value = "/judge", method = RequestMethod.POST)
	public Object selectByPrimaryKey(Integer judgeId) {
		return ResultDataUtil.resData(200, "", judgeService.selectByPrimaryKey(judgeId));
	}
	
	@ApiOperation(value="动态更新判断题" , notes="")
    @ApiImplicitParam(name = "record", value = "判断题对象", required = true, dataType = "Judge",paramType="form")
	@RequestMapping(value = "/judge/update", method = RequestMethod.POST)
	public Object updateByPrimaryKeySelective(Judge record) {
		int status=200;
		String message=null;
		try {
			judgeService.updateByPrimaryKeySelective(record);
			status=200;
			message="更新成功!";
		} catch (Exception e) {
			status=500;
			message="更新失败!";
		}
		return ResultDataUtil.resData(status, message, null);
	}
	
	@ApiOperation(value="根据ID删除判断题" , notes="")
    @ApiImplicitParam(name = "judgeId", value = "判断题ID", required = true, dataType = "Integer")
	@RequestMapping(value = "/judge/delete", method = RequestMethod.POST)
	public Map<String, Object> deleteByPrimaryKey(Integer judgeId) {
		Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
		try {
			judgeService.deleteByPrimaryKey(judgeId);
			resultMap.put("status", 200);
			resultMap.put("message", "删除成功!");
		} catch (Exception e) {
			resultMap.put("status", 500);
			resultMap.put("message", "删除失败!");
		}
		return resultMap;
	}
	
	@ApiOperation(value="动态添加判断题" , notes="")
    @ApiImplicitParam(name = "record", value = "判断题对象", required = true, dataType = "Judge",paramType="form")
	@RequestMapping(value = "/judge/insert", method = RequestMethod.POST)
	public Map<String, Object> insertSelective(Judge record) {
		Map<String, Object> resultMap = new LinkedHashMap<String, Object>();
		try {
			judgeService.insertSelective(record);
			resultMap.put("status", 200);
			resultMap.put("message", "添加成功!");
		} catch (Exception e) {
			resultMap.put("status", 500);
			resultMap.put("message", "添加失败!");
		}
		return resultMap;
	}
}
